<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class GlobalLib{
    
     public static function getSiteUrl(){
        return self::getSiteConfig('url');
    }
    
    public static function getImageUrl(){
        return self::getSiteConfig('image_url');
    }
    
    public static function getSiteConfig($key) {
        $registry = Zend_Registry::getInstance();
        $siteConfig = $registry->get('site');
        return $siteConfig[$key];
    }
    public static function createOrderNo() {
        return date('Ymd') . time();
    }
    public static function query($query, $whereData = NULL) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $stmt = $db->query($query, $whereData);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        return $items;
    }
    public static function viewDate($date, $showTime = false) {
        if (empty($date) || trim($date) == '')
            return '';
        $format = '';
        if ($showTime == true) {
            $format = GlobalLib::getSiteConfig('datetimeformat');
        } else {
            $format = GlobalLib::getSiteConfig('dateformat');
        }
        return date($format, strtotime($date));
    }

    public static function getJsDateFormat() {
        return GlobalLib::getSiteConfig('jsdateformat');
    }

    public static function toMysqlDate($jsDate) {
        $jsDateFormat = GlobalLib::getSiteConfig('jsdateformat');
        $d = '';
        $m = '';
        $y = '';
        switch ($jsDateFormat) {
            case 'dd-mm-yy':
                list($d, $m, $y) = explode('-', $jsDate);
                break;
        }
        return mktime(0, 0, 0, $m, $d, $y);
    }

    public static function toMysqlDateString($jsDate) {
        if (empty($jsDate) || trim($jsDate) == '')
            return '';
        $jsDateFormat = GlobalLib::getSiteConfig('jsdateformat');
        $d = '';
        $m = '';
        $y = '';

        switch ($jsDateFormat) {
            case 'dd-mm-yy':
                list($d, $m, $y) = explode('-', $jsDate);
                break;
            case 'dd/mm/yy':
                list($d, $m, $y) = explode('/', $jsDate);
                break;
            case 'yy/mm/dd':
                list($y, $m, $d) = explode('/', $jsDate);
                break;
        }
        return $y . '-' . $m . '-' . $d;
    }

    public static function fetchAllReferTable($tableName, $valueColumn, $textColumn) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . '';
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $results = array();
        foreach ($items as $item) {
            $results[$item[$valueColumn]] = $item[$textColumn];
        }
        $results[0] = '';
        return $results;
    }        
    
    public static function getComboByForeignKey($fieldName, $tableName, $valueColumn,$foreignkeyColumn, $textColumn, $defaultValue, $multiSelect = false, $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT '.$foreignkeyColumn.',' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } 
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        $html .= '<option value="0">Chưa lựa chọn</option>';
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';       
        return $html;
    }            
    
    public static function getCombo($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $filters = '', $orderBys = NULL, $onclick='', $zeroValueName = 'Chưa lựa chọn') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } 
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        $html .= '<option value="0">'.$zeroValueName.'</option>';        
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';       
        return $html;
    }
    //P: dropdownlist and set multi selected
    //   $defaultValue: string    2,4,5
    public static function getComboMulti($fieldName, $tableName, $valueColumn, $textColumn,$textColumn1=NULL, $defaultValue, $multiSelect = false, $filters = '', $orderBys = NULL, $onclick='', $zeroValueName = 'Chưa lựa chọn') {
        $db = Zend_Db_Table::getDefaultAdapter();
        if($textColumn1 ==NULL){
            $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        } else {
          $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ','.$textColumn1. ' from ' . $tableName . ' '.$filters.' '.$orderBys;  
        }
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" ' . $multiSelectHTML .' '.$onclick .'>';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
            $html = '<select id="' . $fieldName . '" name="' . $fieldName . '[]" ' . $multiSelectHTML .' '.$onclick .'>';
        } 
        
        $html .= $html1;
//        $html .= '<option value="0">'.$zeroValueName.'</option>';        
        foreach ($items as $item) {
            $selected = '';
            if (in_array($item[$valueColumn], explode(',', $defaultValue)))
                $selected = ' selected="selected"';
            if($textColumn1==NULL){
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
            } else {
                 $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]).' - '.str_replace("'", "\'", $item[$textColumn1]) . '</option>';
            }
        }
        $html .= '</select>';       
        return $html;
    }
    public static function getComboByList($fieldName,$value, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '') {
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value=""></option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML . '>';
        $html .= $html1;
        $item = explode(';',$value);
        $countItems = count($item);
        for($i=0;$i<$countItems;$i++) {
            $selected = '';
            if ($defaultValue == $item[$i])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$i] . '" ' . $selected .'>' . $item[$i] . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
   
    public static function getComboByNumber($fieldName,$value, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '') {
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML . '>';
        $html .= $html1;
        for($i=1;$i<=intval($value);$i++) {
            $selected = '';
            if ($defaultValue == $i)
                $selected = ' selected="selected"';
            $html .= '<option value="' . $i . '" ' . $selected .'>' . $i . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
    public static function getComboByArea($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Khu vực</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
     public static function getComboByProvince($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='', $zeroValueName='Tỉnh thành') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">'.$zeroValueName.'</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
     public static function getComboByAgent($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ', address from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Đại Lý/Cửa hàng</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) .' - '.str_replace("'", "\'", $item['address']). '</option>';
        }
        $html .= '</select>';
        return $html;
    }
   public static function getComboByProductCategory($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Nhóm Sản phẩm</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
    public static function getComboByProduct($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Sản phẩm</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
  
    public static function getComboByDistrict($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ' from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Quận Huyện</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) . '</option>';
        }
        $html .= '</select>';
        return $html;
    }
    public static function getName($tableName, $valueColumn, $textColumn){
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT '.$valueColumn.','.$textColumn . ' from ' . $tableName . ' where id= '. $valueColumn.'';
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $results = array();
        foreach ($items as $item) {
            $results[$item[$valueColumn]] = $item[$textColumn];
        }
        return $results[$valueColumn]; 
    }    
    public static function getUserLoginName() {
        $session = new Zend_Session_Namespace('Zend_Auth_User_Info');
        return $session->userInfo['username'];
    }
    public static function checkUserLogin() {
        $session = new Zend_Session_Namespace('Zend_Auth_User_Info');
        if(empty($session) || empty($session->userInfo)){
           return false;
        }
        return true;
    }
    public static function getUserLogin() {
        $session = new Zend_Session_Namespace('Zend_Auth_User_Info');
        return $session->userInfo;
    }
    public static function userLogout() {
        $session = new Zend_Session_Namespace('Zend_Auth_User_Info');
        $session->userInfo = NULL;
        unset($session->userInfo);
        unset($session);
    }
    public static function getLoginId() {
        $identity = Zend_Auth::getInstance()->getIdentity();
        if($identity){
            return $identity->id;
        }
        return 0;
    }  
    public static function getComboByStore($fieldName, $tableName, $valueColumn, $textColumn, $defaultValue, $multiSelect = false, $cssClass = '', $cssStyle = '', $filters = '', $orderBys = NULL, $onclick='') {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = 'SELECT ' . $valueColumn . ',' . $textColumn . ', address from ' . $tableName . ' '.$filters.' '.$orderBys;
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); //PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $multiSelectHTML = '';
        $html1 = '';
        if ($multiSelect) {
            $multiSelectHTML = 'multiple="multiple"';
        } else {
            $html1 = '<option value="0">Đại Lý/Cửa hàng</option>';
        }
        $html = '<select id="' . $fieldName . '" name="' . $fieldName . '" style="' . $cssStyle . '" class="' . $cssClass . '" ' . $multiSelectHTML .' '.$onclick .'>';
        $html .= $html1;
        foreach ($items as $item) {
            $selected = '';
            if ($defaultValue == $item[$valueColumn])
                $selected = ' selected="selected"';
            $html .= '<option value="' . $item[$valueColumn] . '" ' . $selected .'>' . str_replace("'", "\'", $item[$textColumn]) .' - '.str_replace("'", "\'", $item['address']). '</option>';
        }
        $html .= '</select>';
        return $html;
    }
      //
     public static function listQuestion($tam,$vitri){       
       $db = Zend_Db_Table::getDefaultAdapter();
//        $stmt =$db->query('SELECT count(`id`)as tongq FROM `feedback` where `admin_id`=0');
//        $items = $stmt->fetchAll(); 
//        $stmt->closeCursor(); 
//          foreach ($items as $item) {$count_item2=$item['tongq'];} 
//          
        $stmt=$db->query('SELECT count(`id`)as tong FROM `feedback` ');
        $items = $stmt->fetchAll(); 
        $stmt->closeCursor(); 
          foreach ($items as $item) {$count_item1=$item['tong'];} 
          
       $vitri = ($vitri-1) * 4;
       if($tam == 1){
            $query = 'SELECT id,title,user_id,question,answer,admin_id FROM feedback order by modified LIMIT '.$vitri.',4' ;
       }  else {
            $query = 'SELECT id,title,question,user_id,answer,admin_id FROM feedback order by admin_id  LIMIT '.$vitri.',4';
       } 
         
        $stmt = $db->query($query);
        $items = $stmt->fetchAll(); 
        $stmt->closeCursor();        
        $html = ''; $stringt ='';
        if($tam ==1){
            $t = $count_item1/4;
            for($i=1;$i<=$t+1;$i++){
            $stringt1 ='<a href="'.self::getSiteUrl().'default/feedback/index/trang/'.$i.'"> Trang'.$i.'</a>';
            $stringt = $stringt . $stringt1;
            }
        }         
        if($tam !=1){
            $t = $count_item1/4;
            for($i=1;$i<=$t+1;$i++){
            $stringt1 ='<a href="'.self::getSiteUrl().'kinhdoanh/feedback/index/trang/'.$i.'">Trang'.$i.'</a>';
            $stringt = $stringt . $stringt1; 
            }
        }
        foreach ($items as $item) {
//            if($tam !=1){            
                $html11 = ' <div class="row" id="cautraloi'.$item['id'].'">  <form role="form" method="POST" name="EditFeedback" onsubmit="return checkinput();">
                            <div class="form-group">
                                       <input type ="hidden" name="id" id ="user_id" value ="'.$item['id'].'">
                                       <input type ="hidden" name="user_id_feedback" id ="user_id_feedback" value ="'.$item['user_id'].'">
                                       <input type ="hidden" name="title_feedback" id="title_feedback" value="'.$item['title'].'">
                                       <input type ="hidden" name="question_feedback" id="question_feedback" value="'.$item['question'].'"> 
                                <div class="row">
                                    <div class="col-lg-3">
                                        <label>Câu Trả Lời</label>
                                    </div>
                                    <div class="col-lg-12">
                                        <textarea class="ckeditor" name="answer" id="answer"></textarea>                                   
                                    </div>
                                </div>
                            </div>
                            <div class="form-group"><center>
                                <button type="submit" class="btn btn-primary"id="submit">Trả lời</button>
                                <button type="reset" class="btn btn-default" id="reset">Làm lại</button></center>
                            </div>
                        </form></div>';
//            }else{
            if($item['admin_id']==0){
                $str = "";
            }  else {
                $str = GlobalLib::getName('admin',$item['admin_id'],'user_name');
            }
            $html12 = '<div class="row" id="cautraloi'.$item['id'].'"> <div class="cautraloi1">'. $str.'<br></div><div class="img_answer"><br><u><b>Trả lời:</b></u><br></div>'.$item['answer'].'</div>';
//            }
            //hinh do neu chua tra loi. nguoc lai thi tra loi
             if($item['answer']!="") {
                      $ts = '#img_question'.$item['id'].'{
                                    float:left;
                                    background-repeat: no-repeat;
                                    background-size: 60% 60%;

                                    padding: 5%;
                                    padding-right:1%;
                                    width: 10%;hight:auto;
                                    background-image: url("'.self::getImageUrl().'/image/images answer1_1.png");
                                }';
                  }  else {
                      $ts='#img_question'.$item['id'].'{
                                    float:left;
                                    background-repeat: no-repeat;
                                    background-size: 60% 60%;

                                    padding: 5%;
                                    padding-right:1%;
                                    width: 10%;hight:auto;
                                    background-image: url("'.self::getImageUrl().'/image/images answer.png");
                                }';
                  }     
            //hien thi form tra 
            if($tam !=1){    
                  if($item['admin_id']==0){
                            $t= $html11;
                        }  else {                            
                            $t= $html12;
                        }
                 
                $html1 = '<div class="form-group">
                         <div class="row" id="cauhoi'.$item['id'].'"><div id="img_question'.$item['id'].'"></div><b>'.GlobalLib::getName('user', $item['user_id'], 'username').'</b><br><div class="img_question1">'.$item['question'].'</div> </div>
                       '.$t.
                                   '</div>'.
                                   '<script> 
                                        $(document).ready(function(){        
                                            $("#cauhoi'.$item['id'].'").click(function(){
                                                $("#cautraloi'.$item['id'].'").slideToggle("slow");
                                            });  
                                            
                                        });
                                    </script><style>'.$ts . 
                                '#cauhoi'.$item['id'].':hover
                                {   
                                    color: #EEFFDA;background-color:#336699;
                                }               
                                #cauhoi'.$item['id'].'
                                {   hight:auto;
                                    padding:1%;                   
                                    background-color:#e3ecd2;
                                    border:solid 1px #ffffff;
                                    -moz-border-radius-topleft:10px; 
                                    -webkit-border-top-left-radius:10px;
                                    -moz-border-radius-topright:10px;
                                    -webkit-border-top-right-radius:10px;
                                    -moz-border-radius-bottomleft:10px;
                                    -webkit-border-bottom-left-radius:10px;
                                    -moz-border-radius-bottomright:10px; 
                                    -webkit-border-bottom-right-radius:10px;
                                }
                                 #cautraloi'.$item['id'].'
                                {
                                    hight:auto;
                                    padding:3%;                   
                                    background-color:#CCCCCC;
                                    -moz-border-radius-topleft:10px; 
                                    -webkit-border-top-left-radius:10px;
                                    -moz-border-radius-topright:10px;
                                    -webkit-border-top-right-radius:10px;
                                    -moz-border-radius-bottomleft:10px;
                                    -webkit-border-bottom-left-radius:10px;
                                    -moz-border-radius-bottomright:10px; 
                                    -webkit-border-bottom-right-radius:10px;
                                    
                                }      
                                #cautraloi'.$item['id'].'
                                {
                                    padding:3%;
                                    display:none;
                                }               
                            </style>';  
                 
                 $html = $html . $html1; 
            } 
            if($tam == 1){                 
                $html1 = '<div class="form-group">
                          <div class="row" id="cauhoi'.$item['id'].'"><div id="img_question'.$item['id'].'"></div><div class="img_question1">'.$item['question'].'</div> </div>
                       '.$html12.
                   '</div>'.
                   '<script> 
                        $(document).ready(function(){        
                                $("#cauhoi'.$item['id'].'").click(function(){          
                                $("#cautraloi'.$item['id'].'").slideToggle("slow"); 
                             });       
                        });
                    </script><style>'.$ts . 
                    
                '#cauhoi'.$item['id'].':hover
                {   
                    color: #EEFFDA;background-color:#336699;
                } 
                #cauhoi'.$item['id'].'
                {   hight:auto;
                    padding:0%;                   
                    background-color:#e3ecd2;
                    border:solid 1px #ffffff;
                    -moz-border-radius-topleft:10px; 
                    -webkit-border-top-left-radius:10px;
                    -moz-border-radius-topright:10px;
                    -webkit-border-top-right-radius:10px;
                    -moz-border-radius-bottomleft:10px;
                    -webkit-border-bottom-left-radius:10px;
                    -moz-border-radius-bottomright:10px; 
                    -webkit-border-bottom-right-radius:10px;
                }
                 #cautraloi'.$item['id'].'
                {
                    hight:auto;
                    padding:3%;                   
                    background-color:#CCCCCC;
                    border:solid 1px #ffffff;
                    -moz-border-radius-topleft:10px; 
                    -webkit-border-top-left-radius:10px;
                    -moz-border-radius-topright:10px;
                    -webkit-border-top-right-radius:10px;
                    -moz-border-radius-bottomleft:10px;
                    -webkit-border-bottom-left-radius:10px;
                    -moz-border-radius-bottomright:10px; 
                    -webkit-border-bottom-right-radius:10px;
                }      
                #cautraloi'.$item['id'].'
                {
                    padding:3%;
                    display:none;
                }            
            </style>';  
          
            $html = $html . $html1; 
        }
    }
    $stringt ='<div align ="right" id="link">'.$stringt.'</div>';
//    return $html . $stringt . "a". $count_item1;    
     return $html . $stringt ; 
  }
    //
}